/*
 * Task 3. Anagram
 */
import java.util.Scanner;

/**
 * Class for give the output to screen
 * telling whether two words or phrases
 * are anagrams
 *
 * @version 2.1 24 Jan 2013
 * @author Yegor Apolonov
 */
public class Anagram {

    private static String cleanSpace(String str) {
        return str.replaceAll(" ", "");
    }
    
    /**
     * Method for analysis anagrams in phrases 
     *
     * @return boolean result
     */
    private static boolean analyseAnagram(String[] phrase) {
        
        phrase[0] = cleanSpace(phrase[0]).toLowerCase();
        phrase[1] = cleanSpace(phrase[1]).toLowerCase();
    	
        if(phrase[0].length() != phrase[1].length()) return false;
    	
        /**
         * Beginning to edit strings.
         * Cut symbols of first string 
         * from second string
         */
        for(int symbolPos = 0; symbolPos <phrase[0].length(); symbolPos++) {
           phrase[1] = phrase[1].replaceFirst(phrase[0].substring(symbolPos,symbolPos + 1), "");
        }

        return phrase[1].isEmpty();
    }
	
    public static String[] inpString(){

        String[] strings = new String[2];

        System.out.println("Please, enter first phrase");
        strings[0] = new Scanner(System.in).nextLine();

        System.out.println("Please, enter second phrase");
        strings[1] = new Scanner(System.in).nextLine();

    	return strings;
    }

    public static void main(String[] args) {
        System.out.println("Answer about anagram is "
                           + analyseAnagram(inpString()));
    }
}
